package com.weds.edwx.service;

import com.weds.core.base.BaseService;
import com.weds.edwx.entity.*;
import com.weds.edwx.mapper.KtPaibaMapper;
import com.weds.edwx.mapper.SHAttenceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class SHAttenceService extends BaseService {

    @Autowired
    private SHAttenceMapper shAttenceMapper;

    @Autowired
    private KtPaibaMapper ktPaibaMapper;

    public List<SHAttenceEntity> selectDeptUserNums(SHAttenceParamEntity shAttenceParamEntity){
        return shAttenceMapper.selectDeptUserNums(shAttenceParamEntity);
    }

    public List<SHAttenceEntity> getDeptUserNums(SHAttenceParamEntity shAttenceParamEntity){
        return shAttenceMapper.getDeptUserNums(shAttenceParamEntity);
    }

    public SHAttenceEntity selectUserNums(SHAttenceParamEntity shAttenceParamEntity){
        return shAttenceMapper.selecttUserNums(shAttenceParamEntity);
    }
    public SHAttenceEntity selectDepParent(){
        return shAttenceMapper.selectDepParent();
    }

    public SHAttenceEntity selectAttendance(SHAttenceParamEntity shAttenceParamEntity){
        return shAttenceMapper.selectAttendance(shAttenceParamEntity);
    }

    public List<SHUserEntity> selectUserInfo(SHAttenceParamEntity shAttenceParamEntity){
        return shAttenceMapper.selectUserInfo(shAttenceParamEntity);
    }

    public List<SHUserEntity> selectUserList(SHAttenceParamEntity shAttenceParamEntity){
        return shAttenceMapper.selectUserList(shAttenceParamEntity);
    }


    public List<SHUserEntity> selectUserLeave(SHAttenceParamEntity shAttenceParamEntity){
        List<SHUserEntity> list = null;
        if (shAttenceParamEntity.getFlag() == 1){ // 迟到
            list = shAttenceMapper.selectUserCt(shAttenceParamEntity);
        }
        if (shAttenceParamEntity.getFlag() == 2){ // 早退
            list = shAttenceMapper.selectUserZt(shAttenceParamEntity);
        }
        if (shAttenceParamEntity.getFlag() == 3){ // 请假
            list = shAttenceMapper.selectUserLeave(shAttenceParamEntity);
        }
        if (shAttenceParamEntity.getFlag() == 4){ // 旷工
            list = shAttenceMapper.selectUserKg(shAttenceParamEntity);
        }
        if (shAttenceParamEntity.getFlag() == 5){ // 加班
            list = shAttenceMapper.selectUserJb(shAttenceParamEntity);
        }
        return list;
    }

    public KtPaiba selectUserPaiba(KtPaiba ktPaiba){
        return ktPaibaMapper.selectUserPaiba(ktPaiba);
    }

    public List<SHBanciEntity> selectBanci(KtPaiba ktPaiba){
       return ktPaibaMapper.selectBanci(ktPaiba);
    }

    public List<SHBanciTimeEntity> selectBanciTime(String parent){
        return ktPaibaMapper.selectBanciTime(parent);
    }

    public List<KtPaiba> selectDepBanci(SHAttenceParamEntity shAttenceParamEntity){
        return ktPaibaMapper.selectDepBanci(shAttenceParamEntity);
    }

    public List<SHBanciEntity> selectDepBanciGroup(SHAttenceParamEntity shAttenceParamEntity){
        return ktPaibaMapper.selectDepBanciGroup(shAttenceParamEntity);
    }

    public List<String> toArray(KtPaiba ktPaiba){
        List<String> list = new ArrayList<String>();
        if (ktPaiba == null ){
            return list;
        }
        list.add(ktPaiba.getD1() == null?"":ktPaiba.getD1());list.add(ktPaiba.getD2() == null?"":ktPaiba.getD2());
        list.add(ktPaiba.getD3() == null?"":ktPaiba.getD3());list.add(ktPaiba.getD4() == null?"":ktPaiba.getD4());
        list.add(ktPaiba.getD5() == null?"":ktPaiba.getD5());list.add(ktPaiba.getD6() == null?"":ktPaiba.getD6());
        list.add(ktPaiba.getD7() == null?"":ktPaiba.getD7());list.add(ktPaiba.getD8() == null?"":ktPaiba.getD8());
        list.add(ktPaiba.getD9() == null?"":ktPaiba.getD9());list.add(ktPaiba.getD10() == null?"":ktPaiba.getD10());
        list.add(ktPaiba.getD11() == null?"":ktPaiba.getD11());list.add(ktPaiba.getD12() == null?"":ktPaiba.getD12());
        list.add(ktPaiba.getD13() == null?"":ktPaiba.getD13());list.add(ktPaiba.getD14() == null?"":ktPaiba.getD14());
        list.add(ktPaiba.getD15() == null?"":ktPaiba.getD15());list.add(ktPaiba.getD16() == null?"":ktPaiba.getD16());
        list.add(ktPaiba.getD17() == null?"":ktPaiba.getD17());list.add(ktPaiba.getD18() == null?"":ktPaiba.getD18());
        list.add(ktPaiba.getD19() == null?"":ktPaiba.getD19());list.add(ktPaiba.getD20() == null?"":ktPaiba.getD20());
        list.add(ktPaiba.getD21() == null?"":ktPaiba.getD21());list.add(ktPaiba.getD22() == null?"":ktPaiba.getD22());
        list.add(ktPaiba.getD23() == null?"":ktPaiba.getD23());list.add(ktPaiba.getD24() == null?"":ktPaiba.getD24());
        list.add(ktPaiba.getD25() == null?"":ktPaiba.getD25());list.add(ktPaiba.getD26() == null?"":ktPaiba.getD26());
        list.add(ktPaiba.getD27() == null?"":ktPaiba.getD27());list.add(ktPaiba.getD28() == null?"":ktPaiba.getD28());
        list.add(ktPaiba.getD29() == null?"":ktPaiba.getD29());list.add(ktPaiba.getD30() == null?"":ktPaiba.getD30());
        list.add(ktPaiba.getD31() == null?"":ktPaiba.getD31());
        Collections.replaceAll(list,"[X]","99999");
        return list;
    }
    public List<SHBanciEntity> selectBnaciAll(){
        return ktPaibaMapper.selectBanciAll();
    }


    /*public SHAttenceEntity selectDepUserNums(SHAttenceParamEntity shAttenceParamEntity){
        return shAttenceMapper.selectDepUserNums(shAttenceParamEntity);
    }*/
}
